;// 锁屏消息操作公共逻辑
(function($, undefined) {
	$._baselineOperCallback = {
		'1' : function(data) {
			parent.$('#table_list').triggerHandler('reload.table');
			setTimeout(function() {
				parent.layer.closeAll();
			}, 1000);
		},
		'21' : function(data) {
			var $form = $('#form-advertiser-add');
			for ( var name in data.msg) {
				var $el = $form.find('input[name=' + name + ']');
				$el.data('layer', layer.tips(data.msg[name], $el, {
					tipsMore : true,
					time : 0
				}));
			}
		}
	}
})(jQuery);
;
(function($, undefined) {
	// 新建校验
	$(function() {
		var $form = $('#form-advertiser-add');
		var validate = $('#form-advertiser-add').validate({
			errorClass : 'ota-error', // 取消自带样式，使用效果更好的layer的tips提示
			focusInvalid : false,
			focusCleanup : true,
			submitHandler : function(form) { // 表单提交句柄,为一回调函数，带一个参数：form
				$(form).ajaxSubmit({
					dataType : 'json',
					success : function(data, statusText, xhr, $form) {
						$.jsonResult(data, $._baselineOperCallback);
					},
					error : function(xhr, textStatus, errorThrown) {
						console.log('submit error: ' + errorThrown);
						$.jsonResult({
							code : '2'
						});
					}
				});
				return false;
			},
			unhighlight : function(element, errorClass, validClass) {
				$.validateTip(false, element);
			},
			errorPlacement : function(error, element) {
				$.validateTip(true, element, $(error).text());
			},
			ignore : "",
			rules : {
				url : {
					required : true,
					maxlength : 255
				},
				big_icon : {
					required : true,
					maxlength : 255
				},
				icon : {
					required : true,
					maxlength : 255
				}
			},
			messages : {
				icon : {
					required : '请上传图片'
				},
				big_icon : {
					required : '请上传图片'
				}
			}
		});
		$form.on('valid', function(e, data) {
			console.log(e, data);
			validate.settings.unhighlight.call(validate, data['el'], validate.settings.errorClass, validate.settings.validClass);
		});
	});
})(jQuery);